<?php

class Admin_AuthController extends Zend_Controller_Action {
	
	/**
	 * Initialize the action
	 *
	 * @return void
	 */
	public function init() {
	}
	
	/**
	 * The default action
	 *
	 * Displays the admin dashboard
	 *
	 * @return void
	 */
	public function loginAction() {
		if ($this->_request->isPost ()) {
			$username = Bcms_Filter_Post::get ( 'admin_username' ); //参考过滤器
			$password = Bcms_Filter_Post::get ( 'admin_password' );
			
			$auth = new Bcms_Auth ( $username, $password ); //参考Auth认证
			$result = $auth->authenticate ();
			if ($result) {
				$u = new Model_User();
		        $u->log($u->getCurrentUser()->username,'login');	
		        
				$this->_redirect ( '/admin/index/main' );
			} else {
				echo 'The Username Or Password Is Wrong!!';
			}
		
		} 
	
	}
	

    /**
     * Login action
     *
     * kills the authorized user object
     * then redirects to the main index page
     *
     * @return void
     */
    public function logoutAction()
    {
        $u = new Model_User();
		$u->log($u->getCurrentUser()->username,'logout');	
        Bcms_Auth::destroy();
        $this->_redirect('/admin/index');
    }
}
